package cn.jinjimi.domain.data.dto;

import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.base.util.StringUtils;
import cn.jinjimi.app.entity.Advertisement;
import cn.jinjimi.app.store.DatabaseManager;

import java.util.List;

/**
 * Created by Roy
 * Date: 16/8/19
 */
public class AdvDto {
    public List<Advertisement> data;

    public String token;

    /* 从缓存获取数据 */
    public static List<Advertisement> getAdvtisementsByCache(String id) {
        String cache = DatabaseManager.getInstance().getCacheDao().getCacheData(id);
        if (StringUtils.isEmpty(cache))
            return null;

        AdvDto advDto = GsonUtils.fromJson(cache, AdvDto.class);
        if (advDto != null && advDto.data != null)
            return advDto.data;

        return null;
    }
}
